"""
Iterable: 可迭代,可以使用for循环，内部实现了__iter__方法
Iterator: 迭代器,可以使用for循环，也可以使用next方法，内部实现了__iter__和__next__方法
Generator: 生成器,节省内存，惰性求值
"""
from collections.abc import Iterable, Iterator,Generator
l0 = [1,2,3,4]
print(isinstance(l0, Iterable),isinstance(l0,Iterator),isinstance(l0,Generator))

#iter函数可以将可迭代转化为迭代器
l1 = iter(l0)
print(isinstance(l1, Iterable),isinstance(l1,Iterator),isinstance(l1,Generator))

g0 = (i for i in range(10))
print(isinstance(g0, Iterable),isinstance(g0,Iterator),isinstance(g0,Generator))

class MyIter(Generator):

    def __iter__(self):
        return self

    def __next__(self):
        return 0
m0 = MyIter()
print(isinstance(m0, Iterable),isinstance(m0,Iterator),isinstance(m0,Generator))
